package cn.fl.mcr.service.white.impl;

import cn.fl.mcr.service.white.IMcrWhiteInspectService;
import cn.fl.mcr.transform.white.McrWhiteInspectVOTransform;
import cn.fl.mcr.vo.white.McrWhiteInspectVO;
import cn.lionbridgecapital.loan.model.base.Pager;
import cn.lionbridgecapital.loan.model.dto.white.McrWhiteInspectDTO;
import cn.lionbridgecapital.loan.model.exception.BaseException;
import cn.lionbridgecapital.loan.model.exception.BaseExceptionConstant;
import cn.lionbridgecapital.loan.model.utils.CollectionUtils;
import cn.lionbridgecapital.loan.service.api.white.IMcrWhiteInspectApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * @Author: YangXin
 * @Description: 线上白名单验证
 * @CreateTime: 2020-6-24-下午 2:12
 * @Version: 1.0.0
 **/
@Slf4j
@Service
public class McrWhiteInspectServiceImpl implements IMcrWhiteInspectService {

    @Autowired
    private IMcrWhiteInspectApiService mcrWhiteInspectApiService;

    @Override
    public Pager searchListPage(Pager pager) throws BaseException {
        Pager resultPage = this.mcrWhiteInspectApiService.searchListPage(pager);
        List<McrWhiteInspectDTO> resultList = (List<McrWhiteInspectDTO>) resultPage.getResultList();
        if (CollectionUtils.isNotEmpty(resultList)){
            List<McrWhiteInspectVO> mcrWhiteInspectVOS = McrWhiteInspectVOTransform.toVOList(resultList);
            resultPage.setResultList(mcrWhiteInspectVOS);
        }
        return resultPage;
    }

    @Override
    public boolean modifyWhite(McrWhiteInspectDTO mcrWhiteInspectDTO) throws BaseException {
        if (Objects.isNull(mcrWhiteInspectDTO)){
            log.error("[modifyWhite] 修改小贷线上白名单.请求参数为空");
            throw new BaseException(BaseExceptionConstant.COMMON_0001,"请求参数为空");
        }
        return this.mcrWhiteInspectApiService.modifyWhiteList(mcrWhiteInspectDTO);
    }

    @Override
    public Long insertWhite(McrWhiteInspectDTO mcrWhiteInspectDTO) throws BaseException {
        if (Objects.isNull(mcrWhiteInspectDTO)){
            log.error("[modifyWhite] 新增小贷线上白名单.请求参数为空");
            throw new BaseException(BaseExceptionConstant.COMMON_0001,"请求参数为空");
        }
        return this.mcrWhiteInspectApiService.insertWhiteList(mcrWhiteInspectDTO);
    }
}
